<?php
set_time_limit(0);
include_once 'simple_html_dom.php';
function fun($w){

$url="http://dict.youdao.com/search?le=eng&q=".$w."&keyfrom=dict.index";
//echo $url;
$html= file_get_html($url);
$englishE="";
$englishA="";
$english0="";
$info="";
$ee="";
$dict21="";
$kl="";
foreach ($html->find(".pronounce") as $r){
	
	if (strstr($r->innertext,'英')){
		$englishE=$r->find('.phonetic',0)->innertext;
	}elseif(strstr($r->innertext,'美')){
		$englishA=$r->find('.phonetic',0)->innertext;
	}else{
		$english0=$r->find('.phonetic',0)->innertext;
	}
};
$info = $html->find(".trans-container",0)->innertext;
$ee = $html->find("#tEETrans",0)->innertext;
$dict21 = $html->find("#authDictTrans",0)->innertext;
$kl = $html->find("#collinsResult",0)->innertext;
return array('e'=>$englishE,'a'=>$englishA,'o'=>$english0,'i'=>$info,'ee'=>$ee,'d21'=>$dict21,'kl'=>$kl);
}
mysql_connect("localhost","root","");
mysql_select_db("diandi_danci");
mysql_query("set names utf8");
$result = mysql_query("select *from word where id>2072");
while($row = mysql_fetch_array($result)){
	$data = fun($row['word']);
	echo $row["id"]."<br>\n";
	//print_r($data);
	//$sql="update word set symbolE=\"".$data['e']."\",symbolA=\"".$data['a']."\",symbol0=\"".$data['o']."\" where id='".$row['id']."'";
	//echo $sql;
	//mysql_query($sql);
	if(!empty($data['ee'])){
		$sql="INSERT INTO `diandi_danci`.`dict` (`id`, `word_id`, `type`, `explanation`) 
			VALUES (NULL, '".$row['id']."', '1', '".mysql_escape_string($data['ee'])."');";
		//echo $sql;exit;
		mysql_query($sql);
	}
	if(!empty($data['d21'])){
		mysql_query("INSERT INTO `diandi_danci`.`dict` (`id`, `word_id`, `type`, `explanation`)
				VALUES (NULL, '".$row['id']."', '2', '".mysql_escape_string($data['d21'])."');");
	}if(!empty($data['kl'])){
		mysql_query("INSERT INTO `diandi_danci`.`dict` (`id`, `word_id`, `type`, `explanation`)
				VALUES (NULL, '".$row['id']."', '3', '".mysql_escape_string($data['kl'])."');");
	}
	mysql_query("INSERT INTO `diandi_danci`.`dict` (`id`, `word_id`, `type`, `explanation`)
					VALUES (NULL, '".$row['id']."', '0', '".mysql_escape_string($data['i'])."');");
	/*
	if(!empty($data['e'])){
		mysql_query("INSERT INTO `diandi_danci`.`pronunciation` (`id`, `symbol`, `type`, `word_id`)
		 VALUES (NULL, '".$data['e']."', '1', '".$row['id']."');");
	}if(!empty($data['ee'])){
		mysql_query("INSERT INTO `diandi_danci`.`dict` (`id`, `word_id`, `type`, `explanation`) 
			VALUES (NULL, '".$row['id']."', '1', '".$data['ee']."');");
	}if(!empty($data['ee'])){
		mysql_query("INSERT INTO `diandi_danci`.`dict` (`id`, `word_id`, `type`, `explanation`) 
			VALUES (NULL, '".$row['id']."', '1', '".$data['ee']."');");
	}*/
	//exit;
}